﻿using Microsoft.Extensions.Options;
using MoolinkHsmsServer.appSession;
using SuperSocket;
using SuperSocket.Server;
using SuperSocket.SessionContainer;
using superSocketApi;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace MoolinkHsmsServer.appService
{
    public class HsmsAppService<TReceivePackageInfo> : SuperSocketService<TReceivePackageInfo>
        where TReceivePackageInfo : class
    {
        public HsmsAppService(IServiceProvider serviceProvider, IOptions<ServerOptions> serverOptions)
            : base(serviceProvider, serverOptions)
        {

        }

		//protected override async ValueTask OnSessionConnectedAsync(IAppSession session)
		//{
		//    // do something right after the sesssion is connected
		//    await base.OnSessionConnectedAsync(session);
		//}

		//protected override async ValueTask OnSessionClosedAsync(IAppSession session)
		//{
		//    // do something right after the sesssion is closed
		//    await base.OnSessionClosedAsync(session);
		//}

		protected override async ValueTask OnStartedAsync()
        {
			// do something right after the service is started
			//await Task.Factory.StartNew(() =>
			//{
			//	while (true)
			//	{
			//		Thread.Sleep(5000);
			//		//Console.WriteLine("sessionCount:{0},{1}", this.SessionCount.ToString(), this.GetAsyncSessionContainer().GetSessionCountAsync().ToString());

			//		if (GlobalSystem.theHost.Services.GetSessionContainer() != null)
			//		{
			//			foreach (var item in GlobalSystem.theHost.Services.GetSessionContainer().GetSessions())
			//			{
			//				item.SendAsync(Encoding.UTF8.GetBytes("hello,"+ item.SessionID));
			//			}
			//		}
			//		else
			//		{
			//			Console.WriteLine("null");
			//		}


			//	}

			//});

			await Task.Delay(0);
        }

        //protected override async ValueTask OnStopAsync()
        //{
        //    // do something right after the service is stopped
        //}
    }
}
